﻿@model RTW.Models.TUserInfo
@{
    ViewData["Title"] = "UserEdit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section head{
    <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet" />
    <link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" />
    <link href="/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet" />
    <link href="/css/animate.min.css" rel="stylesheet" />
    <link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" />
    <link href="/css/plugins/iCheck/custom.css" rel="stylesheet" />
    <link href="/css/style.min.css?v=4.1.0" rel="stylesheet" />
    <style type="text/css">
        .input-group-addon {
            width: 80px;
        }

        .input-group {
            margin-bottom: 15px;
            text-align: center;
            width: 100%;
        }

        .text-left label {
            font-weight: normal;
            margin-right: 8px;
            margin-left: 2px;
        }

        .checkbox label, .radio label {
            padding-left: 0px;
        }
    </style>

}
<form id="form1" asp-action="UserEdit">
    <div id="dContent">
        <div class="input-group">
            <span class="input-group-addon">账号</span>
            @*<asp:TextBox ID="txtUserAccount" runat="server" CssClass="form-control" dataType="null" Msg="账号不能为空!"></asp:TextBox>*@
            @Html.TextBoxFor(m => m.UserAccount, new { @class = "form-control", dataType = "null", Msg = "账号不能为空!" })
        </div>
        <div class="input-group">
            <span class="input-group-addon">姓名</span>
            @*<asp:TextBox ID="txtUserName" runat="server" CssClass="form-control" dataType="null" Msg="姓名不能为空!"></asp:TextBox>*@
            @Html.TextBoxFor(m => m.UserName, new { @class = "form-control", dataType = "null", Msg = "姓名不能为空!" })
        </div>
        <div class="input-group">
            <span class="input-group-addon">部门</span>
            @*<div id="dOrgs" class="form-control" style="height: 150px; overflow-y: auto; padding-top: 10px; text-align: left;">
                    <div style="text-align: right;">
                        <a class="btn btn-sm btn-warning btn-outline" onclick="SelAll()">全选</a>
                        <a class="btn btn-sm btn-warning btn-outline" onclick="SelNo()">反选</a>
                    </div>
                    <asp:Repeater ID="Repeater1" runat="server">
                        <ItemTemplate>
                            <div class="checkbox i-checks" style="float: left; margin-right: 5px; width: 150px; text-align: left; margin-top: 0px;">
                                <label style="padding-left: 0px;">
                                    <input type="checkbox" value="<%#Eval(" ID") %>" /><i></i><%#Eval("OrgName") %>
                                </label>
                            </div>
                        </ItemTemplate>
                    </asp:Repeater>
                </div>
                <asp:HiddenField ID="hfOrgs" runat="server" />
                <%--<asp:DropDownList ID="ddlOrg" runat="server" CssClass="form-control" dataType="null" Msg="请选择部门!" Visible="false"></asp:DropDownList>--%>*@
            @await Component.InvokeAsync("RTW.Web.Component.DpetOrgList", new { DMID = ViewBag.DMID })
        </div>
        <div class="input-group">
            <span class="input-group-addon">身份</span>
            @*<asp:DropDownList ID="ddlRole" runat="server" CssClass="form-control" dataType="null" Msg="请选择身份!"></asp:DropDownList>*@
            @Html.DropDownListFor(m => m.RoleID, ViewBag.Roles as IEnumerable<SelectListItem>, new { @class = "form-control", dataType = "null", Msg = "请选择身份!" })
        </div>
        <div class="input-group">
            <span class="input-group-addon">手机号</span>
            @*<asp:TextBox ID="txtTel" runat="server" CssClass="form-control"></asp:TextBox>*@
            @Html.TextBoxFor(m => m.Tel, new { @class = "form-control" })
        </div>
        <div class="input-group">
            <span class="input-group-addon">状态</span>
            <div class="form-control text-left">
                <div class="checkbox i-checks" style="float: left; margin-right: 5px; width: 150px; text-align: left; margin-top: 5px;">
                    @Html.CheckBoxFor(m => m.IsUndergoValue)
                    <label style="padding-left: 0px;">
                        离岗
                    </label>
                </div>
            </div>
        </div>
        <div class="input-group">
            <span class="input-group-addon">打印权限</span>
            <div class="form-control text-left">
                <div class="checkbox i-checks" style="float: left; margin-right: 5px; width: 150px; text-align: left; margin-top: 5px;">
                    @Html.CheckBoxFor(m => m.Flag3Value)
                    <label style="padding-left: 0px;">
                        可打印
                    </label>
                </div>
            </div>
        </div>
        <div class="input-group">
            <span class="input-group-addon">编辑权限</span>
            <div class="form-control text-left">
                <div class="checkbox i-checks" style="float: left; margin-right: 5px; width: 150px; text-align: left; margin-top: 5px;">
                    @Html.CheckBoxFor(m => m.EditIDValue)
                    <label style="padding-left: 0px;">
                        可编辑
                    </label>
                </div>
            </div>
        </div>
    </div>
    <div class="zui-footer">
        <button id="btnSave" class="btn btn-primary btn-sm" type="submit">保存</button>

        <button class="btn btn-default btn-sm" type="button" onclick="closePage()">关闭</button>
    </div>

    @Html.HiddenFor(m => m.DMID)
    @Html.HiddenFor(m => m.OrgID)
    @Html.HiddenFor(m => m.ID)
    @Html.HiddenFor(m => m.AddTime)
    @Html.HiddenFor(m => m.CreateDt)
</form>
@section scripts{

    <script src="/js/jquery.min.js?v=2.1.4"></script>
    <script src="/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="/js/plugins/jeditable/jquery.jeditable.js"></script>
    <script src="/js/plugins/dataTables/jquery.dataTables.js"></script>
    <script src="/js/plugins/dataTables/dataTables.bootstrap.js"></script>

    <script src="/js/My97DatePicker/WdatePicker.js"></script>
    <script src="/js/plugins/layer/layer.min.js"></script>
    <script src="/js/plugins/iCheck/icheck.min.js"></script>
    <script src="~/lib/jquery.form/jquery.form.min.js"></script>
    <script src="~/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="~/js/plugins/validate/additional-methods.min.js"></script>
    <script src="/js/verification.js"></script>

    <script type="text/javascript">
        $(function () {
            var Orgs = $("#OrgID").val();
            var arry = Orgs.split(',');

            $("#dOrgs input[type='checkbox']").each(function (i) {
                var v1 = $(this).val();
                var isCheck = false;
                for (var k = 0; k < arry.length; k++) {
                    var v2 = arry[k];
                    if (v1 == v2) {
                        isCheck = true;
                        break;
                    }
                }
                $(this).attr("checked", isCheck);
            })

            $(".i-checks").iCheck({
                checkboxClass: "icheckbox_square-green",
                radioClass: "iradio_square-green"
            })
        })

        $("#dOrgs input[type='checkbox']").on('ifChecked', function (event) {
            CheckClick();
        }).on('ifUnchecked', function (event) {
            CheckClick();
        })

        function CheckClick() {
            var Orgs = "";
            $("#dOrgs input[type='checkbox']:checked").each(function (i) {
                if (i == 0) {
                    Orgs += $(this).val();
                }
                else {
                    Orgs += "," + $(this).val();
                }
            })
            $("#OrgID").val(Orgs);
        }

        //全选
        function SelAll() {
            $("#dOrgs div.icheckbox_square-green").each(function (i) {
                var ck = $(this).hasClass("checked");
                if (ck == false) {
                    $(this).parent().click();
                }
            })
        }

        //反选
        function SelNo() {
            $("#dOrgs div.icheckbox_square-green").each(function (i) {
                $(this).parent().click();
            })
        }

        //提交
        (function ($) {
            $.user = {
                init: function () {

                },
                formSubmit: function () {
                    $("#form1").validate({
                        rules: {
                            UserAccount: {
                                required: true
                            },
                            UserName: {
                                required: true
                            },
                            RoleID: {
                                required: true
                            }
                        },
                        errorPlacement: function (error, element) {
                            //错误消息不为空，提示Msg消息或默认消息
                            if (error[0].textContent != "") {
                                if (error[0].textContent != undefined) {
                                    let msg = element.attr("Msg") ? element.attr("Msg") : error.textContent;
                                    showTip(msg, 2);
                                }
                            }
                        },
                        onkeyup: false,
                        focusCleanup: true,
                        success: "valid",

                        submitHandler: function (form) {
                            //return verfic('tip', '#dContent');
                            //var fRankName = $("select[name='fRankId']").find("option:selected").text();
                            //var fState = $("input[name='fState']").is(':checked');
                            $(form).ajaxSubmit({
                                type: "POST",
                                cache: false,
                                //data: { fRankName: fRankName, fState: fState },
                                dataType: "json",
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    if (XMLHttpRequest.status != 200) {
                                        showTip(errorThrown, 2);
                                    }
                                },
                                success: function (result) {

                                    var state = result.success;
                                    var message = result.msg;
                                    if (state) {
                                        showTip(message, 1, 2);
                                    } else {
                                        showTip(message, 2);
                                    }

                                }
                            });
                        }
                    });
                }
            };
            $(function () {
                $.user.init();
                $.user.formSubmit();
            });
        })(jQuery);
    </script>

}
